/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.elte.progelm2.ejb.simulator;

import hu.elte.progelm2.ejb.entity.Forrest;
import hu.elte.progelm2.ejb.entity.Treetypes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;

/**
 *
 * @author ntb
 */
@Stateless(mappedName = "Simulator")
public class Simulator implements SimulatorRemote {
    
    @PersistenceContext(unitName = "SimulatorPU")
    private EntityManager em;

    /**
     * Default constructor.
     * <br>
     * Initializing Entity Manger.
     */
    public Simulator() {
    }

    public Forrest getForrestById(String id){
        return (Forrest) em.createNamedQuery("Forrest.findById").setParameter("id", Integer.valueOf(id)).getSingleResult();
    }


    /**
     * Get all Forrest.
     * <br>
     * Select * from Forrest;
     * @return List<Forrest> List of Forrests.
     */
    public List<Forrest> getAllForrest() {
        return (List<Forrest>) em.createNamedQuery("Forrest.findAll").getResultList();
    }


    /**
     * Get all TreeTypes
     * <br>
     * Select * from Treetypes;
     * @return List<Treetypes> List of Tree Types.
     */
    public List<Treetypes> getTreeTypes(){
        return (List<Treetypes>) em.createNamedQuery("Treetypes.findAll").getResultList();
    }

    public int AddTree(Treetypes tree){
        em.persist(tree);
        return tree.getId();
    }

}
